from blog.models import Blog
import django_filters as filters


class CharArrayFilter(filters.BaseCSVFilter, filters.CharFilter):

    # def filter(self, qs, value):
    #
    #     if not value:
    #         return qs
    #
    #     # values = value.split(',')
    #     return super(CharArrayFilter, self).filter(qs, value)
    pass


class BlogFilterSet(filters.FilterSet):
    tags = CharArrayFilter(lookup_expr='contains',field_name='tags')

    class Meta:
        model = Blog
        fields = {'tags'}


# class ListFilter(filters.Filter):
#
#     def filter(self, qs, value):
#         if not value:
#             return qs
#
#         self.lookup_expr = 'contains'
#         values = value.split(',')
#         return super(ListFilter, self).filter(qs, values)
#
#
# class BlogFilterSet(filters.FilterSet):
#     tags = ListFilter(name='tags')
#
#     class Meta:
#         model = Blog
#         fields = ['tags']